<template>

  <div class="mcontainer">
    <Header></Header>
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="item.created" placement="top" v-for="(item,index) in blog" :key="index">
          <el-card>
            <h4>
              <router-link :to="{name:'detail',params: {blogId:item.id}}">
               {{ item.title }}
              </router-link>
            </h4>
            <p>{{ item.description }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
    <el-pagination
      class="mpage"
      background
      layout="prev, pager, next"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change= page
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import Header from '../components/Header'
export default {
  name: "Blog",
  components:{Header},
  data(){
    return{
      blog: {},
      currentPage:1,
      total:0,
      pageSize:5
    }
  },
  created() {
    this.page(1)
  },
  methods:{
    page(currentPage){
      this.$axios.get('/blog?currentPage='+currentPage).then(res=>{
        console.log(res)
        this.blog = res.data.data.records
        this.currentPage = res.data.data.current
        this.total = res.data.data.total
        this.pageSize = res.data.data.size
      })
    }
  }
}
</script>

<style scoped>
.mcontainer{
  margin: 0px auto;
}
.mpage{
  margin: 0px auto;
  text-align: center;
}
</style>
